home *** CD-ROM | disk | FTP | other *** search
/ Knitting Made Easy / Knitting.iso / App / Patterns.dxr / Internal_41_Hypertext - Go to Marker.ls < prev    next >
Encoding:
Text File  |  2002-04-18  |  6.1 KB  |  175 lines

  1. property myHyperStyle, myMember, myMarkerList
  2.  
  3. on getBehaviorDescription me
  4.   return "HYPERTEXT - GO TO MARKER" & RETURN & RETURN & "This behavior allows you to use Text member hyperlinks to jump to the various markers of the current movie." & RETURN & RETURN & "You can create links with the words" & RETURN & "  first" & RETURN & "  previous" & RETURN & "  next" & RETURN & "  last" & RETURN & "to navigate between markers, or you can use specific marker names." & RETURN & RETURN & "To create a hyperlink in a Text member, open the Text window and select the word(s) that you wish to use as the anchor.  Now open the Text Inspector and type the name of a marker.  When you run your movie, a click on the anchor text will move the playback head to the chosen marker." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Text members" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Use Hyperlink Styles?" & RETURN & "If you select this option, the anchor text will appear underlined and in blue.  A visited link will automatically appear in pink."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with Text members." & RETURN & RETURN & "Create hyperlinks to navigate to the" & RETURN & "various markers of the current movie." & RETURN & RETURN & "You can use specific marker names or" & RETURN & "the words 'first', 'previous', 'next'" & RETURN & "and 'last'."
  9. end
  10.  
  11. on beginSprite me
  12.   Initialize(me)
  13. end
  14.  
  15. on hyperlinkClicked me, link, range
  16.   JumpToMarker(me, link, range)
  17. end
  18.  
  19. on Initialize me
  20.   myMember = sprite(me.spriteNum).member
  21.   memberType = myMember.type
  22.   if memberType <> #text then
  23.     ErrorAlert(me, #invalidMemberType, memberType)
  24.   end if
  25.   if myHyperStyle then
  26.     myMember.useHypertextStyles = 1
  27.   else
  28.     myMember.useHypertextStyles = 0
  29.   end if
  30.   theLinks = myMember.hyperlinks
  31.   linkCount = theLinks.count
  32.   repeat while linkCount
  33.     theRange = theLinks[linkCount]
  34.     anchorRef = myMember.char[theRange[1]..theRange[2]].ref
  35.     anchorRef.hyperlinkState = #normal
  36.     linkCount = linkCount - 1
  37.   end repeat
  38.   myMarkerList = CreateMarkerList(me)
  39.   SetToVisited(me)
  40. end
  41.  
  42. on JumpToMarker me, link, range
  43.   case link of
  44.     "first":
  45.       go(label(line 1 of the labelList))
  46.     "next":
  47.       go(#next)
  48.     "prev", "previous":
  49.       go(#previous)
  50.     "last":
  51.       go(marker(the maxinteger / 2))
  52.     otherwise:
  53.       linkValue = value(link)
  54.       if (linkValue = link) or (link = ("(" & linkValue & ")")) or (link = "0") then
  55.         linkValue = integer(linkValue)
  56.         go(marker(linkValue))
  57.       else
  58.         theMarker = marker(link)
  59.         if theMarker then
  60.           go(theMarker)
  61.         else
  62.           ErrorAlert(me, #invalidMarker, link)
  63.         end if
  64.       end if
  65.   end case
  66.   SetToVisited(me)
  67. end
  68.  
  69. on SetToVisited me
  70.   hyperMarker = myMarkerList.findPos(marker(0))
  71.   if hyperMarker then
  72.     anchorChar = myMarkerList[hyperMarker]
  73.     if anchorChar then
  74.       myMember.char[anchorChar].hyperlinkState = #Visited
  75.     end if
  76.   end if
  77. end
  78.  
  79. on CreateMarkerList me
  80.   markerlist = [:]
  81.   sort(markerlist)
  82.   lastCheckedMarker = 0
  83.   if marker(1) <> marker(-(the maxinteger) / 2) then
  84.     i = 0
  85.     repeat while i >= -(the maxinteger)
  86.       checkMarker = marker(i)
  87.       if checkMarker = lastCheckedMarker then
  88.         exit repeat
  89.       end if
  90.       lastCheckedMarker = checkMarker
  91.       markerlist.addProp(checkMarker, 0)
  92.       i = -1 + i
  93.     end repeat
  94.   end if
  95.   if marker(0) <> marker(the maxinteger / 2) then
  96.     i = 1
  97.     repeat while i <= the maxinteger
  98.       checkMarker = marker(i)
  99.       if checkMarker = lastCheckedMarker then
  100.         exit repeat
  101.       end if
  102.       lastCheckedMarker = checkMarker
  103.       markerlist.addProp(checkMarker, 0)
  104.       i = 1 + i
  105.     end repeat
  106.   end if
  107.   markerLinks = [:]
  108.   theLinks = myMember.hyperlinks
  109.   linkCount = theLinks.count
  110.   i = 1
  111.   repeat while i <= linkCount
  112.     theRange = theLinks[i]
  113.     theData = myMember.char[theRange[1]].hyperlink
  114.     markerLinks.addProp(theData, theRange)
  115.     i = 1 + i
  116.   end repeat
  117.   i = markerlist.count()
  118.   theLabels = the labelList
  119.   repeat while i
  120.     markerName = theLabels.line[i]
  121.     rangePos = markerLinks.findPos(markerName)
  122.     if not rangePos then
  123.       rangePos = markerLinks.count()
  124.       repeat while rangePos
  125.         if markerLinks.getPropAt(rangePos) = markerName then
  126.           exit repeat
  127.         end if
  128.         rangePos = rangePos - 1
  129.       end repeat
  130.     end if
  131.     if rangePos then
  132.       markerlist[i] = markerLinks[rangePos][1]
  133.     end if
  134.     i = i - 1
  135.   end repeat
  136.   return markerlist
  137. end
  138.  
  139. on ErrorAlert me, theError, Data
  140.   case theError of
  141.     #getPDLError:
  142.       alert("Error: This behavior works only with Text members." & RETURN & RETURN & "Hit OK and then delete this behavior from the sprite." & RETURN & RETURN & "For more information on deleting Behaviors, see the Help system.")
  143.       if the optionDown then
  144.         return [#getPDLError: [#comment: "ERROR:   Wrong member type.   Click 'Cancel'." & RETURN & "                               Use only with Text members.", #format: #string, #range: [EMPTY], #default: EMPTY]]
  145.       end if
  146.     otherwise:
  147.       behaviorName = string(me)
  148.       delete word 1 of behaviorName
  149.       delete char -30001 of behaviorName
  150.       delete char -30001 of behaviorName
  151.       case theError of
  152.         #invalidMemberType:
  153.           if the runMode = "Author" then
  154.             alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & RETURN & "Behavior " & behaviorName & " only works with Text members." & RETURN & RETURN & "Current member type = #" & Data)
  155.           end if
  156.           abort()
  157.         #invalidMarker:
  158.           if the runMode = "Author" then
  159.             alert("BEHAVIOR ERROR: Frame " & the frame & ", Sprite " & me.spriteNum & RETURN & RETURN & "Behavior " & behaviorName & " could not find a marker called " & QUOTE & Data & QUOTE & ".")
  160.           end if
  161.       end case
  162.   end case
  163. end
  164.  
  165. on getPropertyDescriptionList me
  166.   if not (the currentSpriteNum) then
  167.     exit
  168.   end if
  169.   theMember = sprite(the currentSpriteNum).member
  170.   if theMember.type <> #text then
  171.     return ErrorAlert(me, #getPDLError)
  172.   end if
  173.   return [#myHyperStyle: [#comment: "Use the standard hyperlink style?", #format: #boolean, #default: 1]]
  174. end
  175.